﻿
//JS获取浏览器参数
function Request(strName) {
    var strHref = window.document.location.href;
    var intPos = strHref.indexOf("?");
    var strRight = strHref.substr(intPos + 1);
    var arrTmp = strRight.split("&");
    for (var i = 0; i < arrTmp.length; i++) {
        var arrTemp = arrTmp[i].split("=");
        if (arrTemp[0].toUpperCase() == strName.toUpperCase())
            return arrTemp[1];
    }
    return "";
}

//弹出居中窗口
function OpenWindow(url, name, iWidth, iHeight) {
    var url; //转向网页的地址;
    var name; //网页名称，可为空;
    var iWidth; //弹出窗口的宽度;
    var iHeight; //弹出窗口的高度;
    var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //获得窗口的垂直位置;
    var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; //获得窗口的水平位置;
    window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=yes,resizeable=no,location=no,status=no');
}

//JS 替换全部字符串
function ReplaceAll(sourceStr, oldString, newString) {
    return sourceStr.replace(new RegExp(oldString, "g"), newString);
}

//JS 还原Input文本框字符
function RuturnInputStr(sourceStr) {
    sourceStr = sourceStr.replace(new RegExp("<br />", "g"), "\n");
    sourceStr = sourceStr.replace(new RegExp("<br/>", "g"), "\n");
    sourceStr = sourceStr.replace(new RegExp("&nbsp;", "g"), "\t");
    return sourceStr;
}

//JS 替换字符串
function CutString(sourceStr, len, replaceStr) {
    return sourceStr.substring(0, len) + replaceStr;
}

//时间加天数
function DateAdd(dateObj, days) {
    var tempDate = dateObj.valueOf();
    tempDate = tempDate + days * 24 * 60 * 60 * 1000;
    tempDate = new Date(tempDate);
    return tempDate;
}

//将时间转换成字符串
function FormatDateToStr(dateObj) {
    return dateObj.getFullYear() + "-" + (dateObj.getMonth() + 1) + "-" + dateObj.getDate();
}

//字符串转换时间格式
function FormatDateTime(curdate, time) {
    if (time == "") {
        return new Date(Date.parse(curdate.replace(/-/g, "/")));
    }
    return new Date(Date.parse(curdate.replace(/-/g, "/") + " " + time));
}

function FormatDate(datetime) {
    return (FormatDateToStr(FormatDateTime(datetime, ""))).replace("-", "年").replace("-", "月") + "日";
}

function FormatDateMain(datetime) {
    return (FormatDateToStr(FormatDateTime(datetime, ""))).replace("-", "年").replace("-", "月") + "日";
}

//加密字符
function EncodeStr(str) {
    return encodeURIComponent(str)
}

//解密字符
function DecodeStr(str) {
    return decodeURIComponent(str)
}

//将中文转换成unicode字符
//function GBToUnicode(text) {
//    text = escape(text.toString()).replace(/\+/g, "%2B");
//    var matches = text.match(/(%([0-9A-F]{2}))/gi);
//    if (matches) {
//        for (var matchid = 0; matchid < matches.length; matchid++) {
//            var code = matches[matchid].substring(1, 3);
//            if (parseInt(code, 16) >= 128) {
//                text = text.replace(matches[matchid], '%u00' + code);
//            }
//        }
//    }
//    text = text.replace('%25', '%u0025');
//    return text;
//} 

function ReturnAll(text) {
    text = text.replace(new RegExp(/(‘)/g), "'");
    text = text.replace(new RegExp(/(”)/g), "\"");
    text = text.replace(new RegExp(/(；)/g), ";");
    text = text.replace(new RegExp(/(：)/g), ":");
    return text;
}

function GBToUnicode(str) {
    return escape(str).replace(/%/g, "\\").toLowerCase();
}

function UnUnicodeToGB(str) {
    return unescape(str.replace(/\\/g, "%"));
}

function urlGo(id, value, params, http) {
    var found = false;
    for (var i = 0; i < params.length; i++) {
        var param = params[i];
        var arr = param.split('=');
        if (arr[0] == id) {
            params[i] = id + "=" + value;
            found = true;
        }
        if (arr[0] == 'page') {
            params[i] = "page=1";
        }
    }
    if (!found) {
        params.push(id + "=" + value);
    }
    window.location = SITE_URL + http + '?' + params.join('&');
}
